<?php
	class configControl extends commonControl{

		function index(){
			$db = M("config");
			$config = array();
			$config["base"] = $db -> all("tid=1");
			$config["code"] = $db -> all("tid=2");
			$this->assign("config",$config);
			$this->display();
		}

		function config_update(){
			$db = M("config");
			//依次找到名字和值进行修改保存；
			foreach($_POST as $n => $v){
				$where = "name='$n'";
				$data = array("value"=>$v);
				$db->where($where)->save($data);
			}
			//将更改完的数据修改为POST进来的时候格式；
			$config = $db->field("name,value")->all();
			$data = array();
			foreach($config as $v){
				$data[$v['name']]=$v['value'];
			}
			//重写配置文件
			$str = "<?php \nif(!defined('PATH_HD'))exit;\nreturn " . var_export($data, true) . ";\n?>";
			file_put_contents("./data/config/config.php", $str);
			$this->success("修改配置文件成功");
		}
	}
?>